<?php
error_reporting(E_ALL);
// 本文档自动生成，仅供测试运行
class IndexAction extends Action
{
	public function __construct()
	{
		parent::__construct();
		R ( "Admin.mycache", 'getsetting' );
		$syscfg = S('setting');
		$this->assign('address',$syscfg[0]);
		$this->assign('education',$syscfg[1]);
		$this->assign('lvshu',$syscfg[2]);
		$this->assign('banxue',$syscfg[3]);
		$this->assign('yuanxiao',$syscfg[4]);
	}
    /**
    +----------------------------------------------------------
    * 首页显示
    +----------------------------------------------------------
    */
    public function index()
    {
    	$syscfg = S('setting');
    	$this->assign('address',$syscfg[0]);
    	$this->assign('education',$syscfg[1]);
    	$this->assign('lvshu',$syscfg[2]);
    	$this->assign('banxue',$syscfg[3]);
    	$this->assign('yuanxiao',$syscfg[4]);
    	$this->assign('title',C("CFG_TITLE"));
    	$this->assign('keyword',C('CFG_KEYWORD'));
    	$this->assign('description',C('CFG_DESCRIPTION'));
    	
    	
    	if(isset($_REQUEST['address']) && $_REQUEST['address'] !='-1')
    	{
    		$where['address'] = array(array('eq',$_REQUEST['address']));
    	}
    	if(isset($_REQUEST['belonging']) && $_REQUEST['belonging'] !='-1')
    	{
    		$where['belonging'] = array(array('eq',$_REQUEST['belonging']));
    	}
    	if(isset($_REQUEST['typeofinstitution']) && $_REQUEST['typeofinstitution'] !='-1')
    	{
    		$where['typeofinstitution']=array(array('eq',$_REQUEST['typeofinstitution']));
    	}
    	if(isset($_REQUEST['banxue']) && $_REQUEST['banxue'] !='-1')
    	{
    		$where['schooltype'] = array(array('eq',$_REQUEST['banxue']));
    	}
    	if(isset($_REQUEST['education']) && $_REQUEST['education'] !='-1')
    	{
    		$where['education'] = array(array('eq'),$_REQUEST['education']);
    	}
    	if(isset($_REQUEST['schoolname']))
    	{
    		$where['title']=array(array('like','%'.trim($_REQUEST['schoolname']).'%'));
    	}
    	$DB = M("school");
    	import ( "ORG.Util.Page" );
		$listRows = 10; //每页显示的条数
		$count = $DB->where($where)->count();
		$p = new Page($count, $listRows);
		$list = $DB->where($where)->order('id desc')->limit($p->firstRow,$p->listRows)->select();
    	$page = $p->show();
    	
    	
    	$DB_zy = M('schoolspeciality');
    	foreach($list as $k=>$v)
    	{
    		$list[$k]['address'] = $syscfg[0][$v['address']];
    		$list[$k]['belonging'] = $syscfg[2][$v['belonging']];
    		$list[$k]['education'] = $syscfg[1][$v['education']];
    		$list[$k]['schooltype'] = $syscfg[3][$v['schooltype']];
    		$list[$k]['typeofinstitution'] = $syscfg[4][$v['typeofinstitution']];
    		$list[$k]['zy'] = $DB_zy->where('schoolid = '.$v['id'])->count();	
    		$list[$k]['attach'] = str_replace(array('1','2','3'),array('985','211','研究生院'),$v['attach']);
    	}
    	$this->assign('list',$list);
    	$this->assign('page',$page);
    	$this->display();
    	
    }

   
    public function head()
    {
    	$this->display('index');
    }
    
    //学校简介
    public function about()
    {
    	if(!isset($_REQUEST['schoolid']))
    	{
    		exit('参数错误');
    	}

    	$id = $_REQUEST['schoolid'];
    	$DB = M('school');
    	$school = $DB->where('id='.$id)->find();
    	
    	$DB_jj = M("about");
    	$where['schoolid'] = array(array('eq',$school['id']));
    	$cnt = $DB_jj->where($where)->find();
    	$this->assign('title',C("CFG_TITLE").'-'.$school['title']);
    	$this->assign('keyword',C('CFG_KEYWORD'));
    	$this->assign('description',C('CFG_DESCRIPTION'));
    	$this->assign('dh_title',$school['title']);
    	$this->assign('cnt',$cnt);
    	$this->display();
    }
    
    //显示子栏目信息
    public function itemlist()
    {
    	if(!isset($_REQUEST['schoolid']) || !isset($_REQUEST['type']))
    	{
    		exit('参数错误');
    	}

    	
    	$schoolid = $_REQUEST['schoolid'];
    	$type = $_REQUEST['type'];
    	$type_tit_arr = array (0 => '院系设置', 1 => '招生简章', 2 => '往年录取信息', 3 => '录取结果公示', 4 => '录取规则', 5 => '体检要求', 6 => '收费项目', 7 => '奖学金设置', 8 => '食宿条件', 9 => '基础设施', 10 => '公示栏', 11 => '毕业生就业', 12 => '答考生问', 13 => '联系办法', 14 => '其他' );
    	$DB_school = M('school');
    	$school = $DB_school->where('id='.$schoolid)->find();
    	$this->assign('school',$school);
    	$this->assign('title',C("CFG_TITLE").'-'.$school['title'].'-'.$type_tit_arr[$type]);
    	$this->assign('keyword',C('CFG_KEYWORD'));
    	$this->assign('description',C('CFG_DESCRIPTION'));
    	$this->assign('type_name',$type_tit_arr[$type]);		//模块名称
    	$DB = M('schoolchilditem');
    	$where['schoolid'] = array(array('eq',$schoolid));
    	$where['type'] = array(array('eq',$type));
    	$this->assign('dh_title',$school['title']);
    	
    	import ( "ORG.Util.Page" );
		$listRows = 10; //每页显示的条数
		$count = $DB->where($where)->count();
		$p = new Page($count,$listRows);
		$list = $DB->where($where)->limit($p->firstRow,$p->listRows)->order('id desc')->select();
		$page = $p->show();
		$this->assign('list',$list);
		$this->assign('page',$page);
		$this->display('itemlist');
    }
    //子栏目具体内容
    public function itemcnt()
    {
    	if(!isset($_REQUEST['id']))
    	{
    		exit('参数错误');
    	}

    	
    	$type_tit_arr = array (0 => '院系设置', 1 => '招生简章', 2 => '往年录取信息', 3 => '录取结果公示', 4 => '录取规则', 5 => '体检要求', 6 => '收费项目', 7 => '奖学金设置', 8 => '食宿条件', 9 => '基础设施', 10 => '公示栏', 11 => '毕业生就业', 12 => '答考生问', 13 => '联系办法', 14 => '其他' );
    	
    	$id = $_REQUEST['id'];
    	$DB =M('schoolchilditem');
    	$cnt = $DB->where('id='.$id)->find();
    	$this->assign('cnt',$cnt);
    	$this->assign('title',C("CFG_TITLE").'-'.$type_tit_arr[$cnt['type']] . '-' .$cnt['title']);
    	$this->assign('keyword',C('CFG_KEYWORD'));
    	$this->assign('description',C('CFG_DESCRIPTION'));
    	$this->assign('type',$type_tit_arr);
    	$this->display('itemcnt');
    }
    
    //招生计划
    public function plan()
    {
    	if(!isset($_REQUEST['schoolid']))
    	{
    		exit('参数错误');
    	}

    	
    	$schoolid = $_REQUEST['schoolid'];
    	$type = '招生计划';
    	//$type_tit_arr = array (0 => '院系设置', 1 => '招生简章', 2 => '往年录取信息', 3 => '录取结果公示', 4 => '录取规则', 5 => '体检要求', 6 => '收费项目', 7 => '奖学金设置', 8 => '食宿条件', 9 => '基础设施', 10 => '公示栏', 11 => '毕业生就业', 12 => '答考生问', 13 => '联系办法', 14 => '其他' );
    	//院校信息
    	$DB_school = M('school');
    	$school = $DB_school->where('id='.$schoolid)->find();
    	$this->assign('school',$school);
    	$this->assign('title',C("CFG_TITLE").'-'.$school['title'].'-'.$type);
    	$this->assign('keyword',C('CFG_KEYWORD'));
    	$this->assign('description',C('CFG_DESCRIPTION'));
    	$this->assign('type_name',$type);
    	$syscfg =S('setting');
    	$this->assign('address',$syscfg[0]);
    	//如果有add参数，调用当前地区下的列表
    	if(isset($_REQUEST['add']))
    	{
    		$add = $_REQUEST['add'];
    		$planid = $_REQUEST['planid'];
    		$this->assign('address',$syscfg[0][$add]);
    		if(isset($_REQUEST['speid']))
    		{
    			$DB = D('plancntview');
    			$where['specialityid'] = array('eq',$_REQUEST['speid']);
    			$list = $DB->where($where)->select();
    			$this->assign('content',$list);
    			$this->assign('edu',$syscfg[1]);		//学历层次
    			$this->assign('plantype',$syscfg[6]);	//计划类型
    			$this->assign('sub',$syscfg[7]);			//科类
    			$this->display('plancontent');
    		}else
    		{
    		$DB = D('plancntview');
    		$where['address'] = array('eq',$add);
    		$where['pid'] = array('eq',$planid);
    		$list = $DB->where($where)->group('specialityid')->select();
    		$this->assign('list',$list);
    		
    		$this->display('planspeciality');
    		}
    		exit();
    	}
    	
    	
    	//如果没有planid 则输出该院校所有年份的计划
    	if(!isset($_REQUEST['planid']))
    	{
	    	//招生计划
	    	$planDB = D('planview');
	    	$plan_list = $planDB->where('schoolid='.$schoolid)->select();
			$this->assign('plan_list',$plan_list);
	    	$this->display('plan_list');
    	}else
    	{
    		$planid = $_REQUEST['planid'];
    		$DB = M('recruitingplanattached');
    		$list = $DB->where('pid='.$planid)->group('address')->select();
			$this->assign('list',$list);

			$this->display('planaddress');
    	}
    }
    
    
    //招生专业
    public function speciality()
    {
    	if(!isset($_REQUEST['schoolid']))
    	{
    		exit('参数错误');
    	}  	

    	
    	$schoolid = $_REQUEST['schoolid'];
    	$DB_SCHOOL = M('school');
    	$school = $DB_SCHOOL->where('id='.$schoolid)->find();
    	$this->assign('school',$school);
    	$DB = D('specialityview');
    	$where['schoolid'] = array('eq',$schoolid);
    	$list = $DB->where($where)->order('specialityid')->select();
		$this->assign('list',$list);
		$this->display('speciality');
    }
    
	public function search_speciality()
    {
    	$syscfg = S('setting');
    	$this->assign('address',$syscfg[0]);
    	$this->assign('education',$syscfg[1]);
    	$this->assign('lvshu',$syscfg[2]);
    	$this->assign('banxue',$syscfg[3]);
    	$this->assign('yuanxiao',$syscfg[4]);
    	
    	$this->assign('title',C("CFG_TITLE"));
    	$this->assign('keyword',C('CFG_KEYWORD'));
    	$this->assign('description',C('CFG_DESCRIPTION'));
    	
    	
    	if(isset($_REQUEST['address']) && $_REQUEST['address'] !='-1')
    	{
    		$where['address'] = array(array('eq',$_REQUEST['address']));
    	}
    	if(isset($_REQUEST['belonging']) && $_REQUEST['belonging'] !='-1')
    	{
    		$where['belonging'] = array(array('eq',$_REQUEST['belonging']));
    	}
    	if(isset($_REQUEST['typeofinstitution']) && $_REQUEST['typeofinstitution'] !='-1')
    	{
    		$where['typeofinstitution']=array(array('eq',$_REQUEST['typeofinstitution']));
    	}
    	if(isset($_REQUEST['banxue']) && $_REQUEST['banxue'] !='-1')
    	{
    		$where['schooltype'] = array(array('eq',$_REQUEST['banxue']));
    	}
    	if(isset($_REQUEST['education']) && $_REQUEST['education'] !='-1')
    	{
    		$where['education'] = array(array('eq'),$_REQUEST['education']);
    	}
    	if(isset($_REQUEST['specialityname']))
    	{
    		$where['spetit']=array(array('like','%'.trim($_REQUEST['specialityname']).'%'));
    	}
    	$DB = D("searchspeview");
    	import ( "ORG.Util.Page" );
		$listRows = 10; //每页显示的条数
		$count = $DB->where($where)->count();
		$p = new Page($count, $listRows);
		$list = $DB->where($where)->order('id desc')->limit($p->firstRow,$p->listRows)->select();
    	$page = $p->show();
    	$DB_zy = M('schoolspeciality');
    	foreach($list as $k=>$v)
    	{
    		$list[$k]['address'] = $syscfg[0][$v['address']];
    		$list[$k]['belonging'] = $syscfg[2][$v['belonging']];
    		$list[$k]['education'] = $syscfg[1][$v['education']];
    		$list[$k]['schooltype'] = $syscfg[3][$v['schooltype']];
    		$list[$k]['typeofinstitution'] = $syscfg[4][$v['typeofinstitution']];
    		$list[$k]['zy'] = $DB_zy->where('schoolid = '.$v['id'])->count();	
    		$list[$k]['attach'] = str_replace(array('1','2','3'),array('985','211','研究生院'),$v['attach']);
    	}
    	$this->assign('list',$list);
    	$this->assign('page',$page);    	
    	$this->display('index');
    	
    }
    
    public function specialitycnt()
    {
    	if(!isset($_REQUEST['id']) || !isset($_REQUEST['schoolid']))
    	{
    		exit('参数错误');
    	}
    	    	
    	$schoolid = $_REQUEST['schoolid'];
    	$type = '专业介绍 ';
    	//$type_tit_arr = array (0 => '院系设置', 1 => '招生简章', 2 => '往年录取信息', 3 => '录取结果公示', 4 => '录取规则', 5 => '体检要求', 6 => '收费项目', 7 => '奖学金设置', 8 => '食宿条件', 9 => '基础设施', 10 => '公示栏', 11 => '毕业生就业', 12 => '答考生问', 13 => '联系办法', 14 => '其他' );
    	//院校信息
    	$DB_school = M('school');
    	$school = $DB_school->where('id='.$schoolid)->find();
    	$this->assign('school',$school);
    	$this->assign('title',C("CFG_TITLE").'-'.$school['title'].'-'.$type);
    	$this->assign('keyword',C('CFG_KEYWORD'));
    	$this->assign('description',C('CFG_DESCRIPTION'));
    	$this->assign('type_name',$type);
    	$this->assign('dh_tit',$school['title']);
    	
    	$DB = M('schoolspeciality');
    	$cnt = $DB->where('id='.$_REQUEST['id'])->find();
    	$this->assign('cnt',$cnt);
    	$this->display('specontent');
    }
    
    
    public function recommend()
    {
    	$DB = M('school');
    	$list = $DB->where('recommend = 1')->limit('0,10')->select();
    	$this->assign('list',$list);
    	$this->display();
    }
}
?>